package reone.android.anytest.MyMovieRecorderTest;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import java.io.IOException;

import reone.android.anytest.MyMovieRecorderTest.view.MyMovieRecorderView;
import reone.android.anytest.R;
import reone.android.anytest.Util.LogUtil;

public class MyMovieActivity extends Activity implements View.OnClickListener {

    private Button beginBtn,stopBtn,playBtn,stopPlayBtn;
    private MyMovieRecorderView mRecorderView;
    private Context mContext;
    private String tempVideoName = "tempFile";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_movie);
        mRecorderView = (MyMovieRecorderView) findViewById(R.id.my_movieRecorderView);
        beginBtn = (Button)findViewById(R.id.Begin);
        stopBtn = (Button)findViewById(R.id.Stop);
        playBtn = (Button)findViewById(R.id.Play);
        stopPlayBtn = (Button)findViewById(R.id.StopPlaying);
        beginBtn.setOnClickListener(this);
        stopBtn.setOnClickListener(this);
        playBtn.setOnClickListener(this);
        stopPlayBtn.setOnClickListener(this);
        mContext = this;
    }

    @Override
    public void onClick(View v) {
        try{
            switch (v.getId()){
                case R.id.Begin:
                    beginRecorder();
                    break;
                case R.id.Stop:
                    stopRecorder();
                    break;
                case R.id.Play:
                    playVideo();
                    break;
                case R.id.StopPlaying:
                    stopPlayViedo();
                    break;
            }
        }catch (Exception e){
            LogUtil.out("Activity OnClick catch e");
            e.printStackTrace();
        }
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    private void stopPlayViedo() {
        mRecorderView.stopPlayVideo();
    }

    private void playVideo() throws IOException {
       mRecorderView.startPlayVideo(tempVideoName);
    }

    private void stopRecorder() {
        mRecorderView.stopRecorder();
    }

    private void beginRecorder() throws IOException {
        mRecorderView.startRecorder(tempVideoName);
    }
}
